﻿@inherits BaseComponent

<Space Size="@("24")">
    <SpaceItem>
        <Tooltip Title="系统首页"><Icon Type="home" OnClick="@(e=>OnItemClick("home"))" /></Tooltip>
    </SpaceItem>
    <SpaceItem>
        <Tooltip Title="@FullScreenTitle"><Icon Type="@FullScreenIcon" OnClick="OnFullScreen" /></Tooltip>
    </SpaceItem>
    <SpaceItem>
        <Dropdown>
            <Overlay>
                <Menu>
                    <MenuItem @key="0" OnClick="@(e=>OnItemClick("profile"))">
                        <Icon Type="user" Theme="outline" />
                        <span>个人中心</span>
                    </MenuItem>
                    <MenuItem @key="1" OnClick="@(e=>OnItemClick("logout"))">
                        <Icon Type="poweroff" Theme="outline" />
                        <span>安全退出</span>
                    </MenuItem>
                </Menu>
            </Overlay>
            <ChildContent>
                <a class="ant-dropdown-link" @onclick:preventDefault>
                    @CurrentUser.Name <Icon Type="down" />
                </a>
            </ChildContent>
        </Dropdown>
    </SpaceItem>
    <SpaceItem>
        <Tooltip Title="系统设置"><Icon Type="more" OnClick="@(e=>showSetting=true)" /></Tooltip>
    </SpaceItem>
</Space>

<Drawer Closable="true" @bind-Visible="showSetting" Placement="right" Title='("系统设置")' Width="300">
    <Known.AntBlazor.Components.SettingForm />
</Drawer>

@code {
    private bool showSetting = false;
    private bool isFullScreen = false;
    private string FullScreenTitle => isFullScreen ? "退出全屏" : "全屏显示";
    private string FullScreenIcon => isFullScreen ? "fullscreen-exit" : "fullscreen";

    [Parameter] public Action<string> OnMenuClick { get; set; }

    private void OnItemClick(string id) => OnMenuClick?.Invoke(id);

    private void OnFullScreen()
    {
        isFullScreen = !isFullScreen;
        if (isFullScreen)
            JS.OpenFullScreen();
        else
            JS.CloseFullScreen();
    }
}